package cn.fxyz.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import cn.fxyz.dao.FoodDao;
import cn.fxyz.entity.Food;
import cn.fxyz.page.PageBean;
import cn.fxyz.service.FoodService;

public class FoodServiceImpl implements FoodService {
	private FoodDao foodDao;
	public Food findById(Food food) {
		return foodDao.selectById(food.getId());
	}
	public FoodDao getFoodDao() {
		return foodDao;
	}
	public void setFoodDao(FoodDao foodDao) {
		this.foodDao = foodDao;
	}
	
	//查询所有餐桌 + 条件查询 + 分页查询
	public PageBean<Food> findAll(Food food, int pageNum,
			int pageSize,Integer typeid) {
		StringBuffer buffer = new StringBuffer();
		List<Object> paramList = new ArrayList<Object>();
		//条件查询
		if(typeid!=null) {
			buffer.append(" and foodtype_id = ?");
			paramList.add(typeid);
		}
		String hql = buffer.toString();
		Object[] params = paramList.toArray();
		//分页
		//总记录数
		int totalRecord = foodDao.getTotalRecord(hql,params);
		//创建对象
		PageBean<Food> pageBean = new PageBean<Food>(pageNum, pageSize, totalRecord);
		//分页数据
		List<Food> data = foodDao.selectAll(hql, params,pageBean.getStartIndex(),pageBean.getPageSize());
		pageBean.setData(data);
		return pageBean;
	}

	
	//后台功能
    /**
     * 查询Service层接口实现类
     */
	
	public List<Food> getFood(String id, String foodname, String foodtype) {
		// TODO Auto-generated method stub
		return foodDao.getFood(id,foodname,foodtype);
	}
	
	public void addFood(Food food) {
		// TODO Auto-generated method stub
		foodDao.addFood(food);
	}
	
	public List<Food> findAll() {
		// TODO Auto-generated method stub
		return foodDao.getAll();
	}
	
	public boolean deleteFood(String id) {
		// TODO Auto-generated method stub
		return foodDao.deleteFood(id);
	}
	
	public Food getFood(String id) {
		// TODO Auto-generated method stub
		return foodDao.getFood(id);
	}
	
	public void modifyFood(Food food) {
		foodDao.update(food);
	}
	
}
